package com.zfl.thread.day01;


import lombok.AllArgsConstructor;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.UUID;

@AllArgsConstructor
class FileThread extends Thread{
    private String url;
    private String fileName;


    @Override
    public void run() {
        super.run();
        try {
            FileUtils.copyURLToFile(new URL(this.url),new File("d:\\images\\"+this.fileName));
            System.out.println(Thread.currentThread().getName()+"-下载图片成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}


public class Filedownload {

    public static void main(String[] args) {
        HashMap<String,String> map = new HashMap<>();
        map.put("https://img2.baidu.com/it/u=2935298851,1106259291&fm=253&app=138&f=JPEG?w=800&h=855", UUID.randomUUID().toString()+".jpg");
        map.put("https://gips0.baidu.com/it/u=4187026265,3633201131&fm=3074&app=3074&f=JPEG",UUID.randomUUID().toString()+".jpg");
        map.put("https://pic.rmb.bdstatic.com/bjh/video/99fa8408b0b1ea96b3b16457a1ebf945.jpeg?for=bg",UUID.randomUUID().toString()+".jpg");
        map.put("https://i2.hdslb.com/bfs/archive/5ea0233dad6c6f18347f082ab62618dbbfcdfb02.jpg",UUID.randomUUID().toString()+".jpg");
        map.put("https://pic.rmb.bdstatic.com/bjh/bb8184a5bf4d/241114/2f71553f12b0bf89c5e08f06de5c9660.jpeg",UUID.randomUUID().toString()+".jpg");
        map.forEach((url,fileName)->{
            new FileThread(url,fileName).start();
        });

    }
}
